#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define fi first
#define se second
using namespace std;
const int N = 5e6+5;
int T,n,m,maxn;
int va[N],c[N];
bool vis[N];
int num()
{
    for(int i=1;i<=n;i++)
    {
        for(int j=i-1;j>=1;j--)
        {
            if(vis[j]==vis[i])
            {
                if(va[i]==va[j]) c[i] = va[i];
                else c[i] = 0;
                break;
            }
        }
    }
    int ans = 0;
    for(int i=1;i<=n;i++) ans += c[i];
    return ans;
}
void dfs(int now,int se)
{
    vis[now] = se;
    if(now==n)
    {
        maxn = max(maxn,num());
        for(int i=1;i<=n;i++) c[i] = 0;
        return;
    }
    dfs(now+1,1);
    dfs(now+1,0);
}
signed main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    IOS;
    cin>>T;
    while(T--)
    {
        maxn = 0;
        cin>>n;
        for(int i=1;i<=n;i++) cin>>va[i];
        dfs(0,0);
        cout<<maxn<<"\n";
    }
}
